package morenoapp.components.common.table.renderer;

import java.awt.AWTException;
import java.awt.AWTKeyStroke;
import java.awt.Color;
import java.awt.Component;
import java.awt.ComponentOrientation;
import java.awt.Container;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.Event;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.GraphicsConfiguration;
import java.awt.HeadlessException;
import java.awt.Image;
import java.awt.ImageCapabilities;
import java.awt.MenuComponent;
import java.awt.Point;
import java.awt.PopupMenu;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.dnd.DropTarget;
import java.awt.event.ComponentListener;
import java.awt.event.FocusListener;
import java.awt.event.HierarchyBoundsListener;
import java.awt.event.HierarchyListener;
import java.awt.event.InputMethodListener;
import java.awt.event.KeyListener;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.event.MouseWheelListener;
import java.awt.im.InputContext;
import java.awt.im.InputMethodRequests;
import java.awt.image.ColorModel;
import java.awt.image.ImageObserver;
import java.awt.image.ImageProducer;
import java.awt.image.VolatileImage;
import java.beans.PropertyChangeListener;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.util.EventListener;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import javax.accessibility.AccessibleContext;
import javax.swing.JTable;
import javax.swing.table.TableCellRenderer;
import morenoapp.MorenoApp;
import morenoapp.model.data.MorenoRespondentFace;

/**
 *
 * @author root
 */
public class RespondentProxyTableCellRenderer extends Component implements TableCellRenderer {
    protected TableCellRenderer delegate;
    protected Component delegateComponent;
    private boolean drawGrayBackground = false;

    public RespondentProxyTableCellRenderer(TableCellRenderer delegate) {
        this.delegate = delegate;
        this.delegateComponent = (Component) delegate;
    }

    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
        delegate.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
        delegateComponent.setBackground(null);
        List<MorenoRespondentFace> respondents = MorenoApp.getModel().getRespondentsList();
        if (respondents.size()>row){
            MorenoRespondentFace resp = respondents.get(row);
            //delegateComponent.setForeground(resp.getSex().getColor());
            drawGrayBackground = resp.isPassedPoll();
        } else {
            drawGrayBackground = false;
        }

        
        return this;
    }

    @Override
    public void paint(Graphics g) {
        setBackground(Color.WHITE);
        super.paint(g);
        if (drawGrayBackground) {
            Color backup = g.getColor();
            g.setColor(Color.lightGray);
            Rectangle r = getBounds();
            for (int x = -r.height; x < r.width; x += 5) {
                g.drawLine(x, 0, x + r.height, r.height);
            }
            g.setColor(backup);
        }
        delegateComponent.paint(g);
    }

    @Override
    public boolean action(Event evt, Object what) {
        return delegateComponent.action(evt, what);
    }

    @Override
    public synchronized void add(PopupMenu popup) {
        delegateComponent.add(popup);
    }

    @Override
    public synchronized void addComponentListener(ComponentListener l) {
        delegateComponent.addComponentListener(l);
    }

    @Override
    public synchronized void addFocusListener(FocusListener l) {
        delegateComponent.addFocusListener(l);
    }

    @Override
    public void addHierarchyBoundsListener(HierarchyBoundsListener l) {
        delegateComponent.addHierarchyBoundsListener(l);
    }

    @Override
    public void addHierarchyListener(HierarchyListener l) {
        delegateComponent.addHierarchyListener(l);
    }

    @Override
    public synchronized void addInputMethodListener(InputMethodListener l) {
        delegateComponent.addInputMethodListener(l);
    }

    @Override
    public synchronized void addKeyListener(KeyListener l) {
        delegateComponent.addKeyListener(l);
    }

    @Override
    public synchronized void addMouseListener(MouseListener l) {
        delegateComponent.addMouseListener(l);
    }

    @Override
    public synchronized void addMouseMotionListener(MouseMotionListener l) {
        delegateComponent.addMouseMotionListener(l);
    }

    @Override
    public synchronized void addMouseWheelListener(MouseWheelListener l) {
        delegateComponent.addMouseWheelListener(l);
    }

    @Override
    public void addNotify() {
        delegateComponent.addNotify();
    }

    @Override
    public synchronized void addPropertyChangeListener(PropertyChangeListener listener) {
        delegateComponent.addPropertyChangeListener(listener);
    }

    @Override
    public synchronized void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) {
        delegateComponent.addPropertyChangeListener(propertyName, listener);
    }

    @Override
    public void applyComponentOrientation(ComponentOrientation orientation) {
        delegateComponent.applyComponentOrientation(orientation);
    }

    @Override
    public boolean areFocusTraversalKeysSet(int id) {
        return delegateComponent.areFocusTraversalKeysSet(id);
    }

    @Override
    public Rectangle bounds() {
        return delegateComponent.bounds();
    }

    @Override
    public int checkImage(Image image, ImageObserver observer) {
        return delegateComponent.checkImage(image, observer);
    }

    @Override
    public int checkImage(Image image, int width, int height, ImageObserver observer) {
        return delegateComponent.checkImage(image, width, height, observer);
    }

    @Override
    public boolean contains(int x, int y) {
        return delegateComponent.contains(x, y);
    }

    @Override
    public boolean contains(Point p) {
        return delegateComponent.contains(p);
    }

    @Override
    public Image createImage(ImageProducer producer) {
        return delegateComponent.createImage(producer);
    }

    @Override
    public Image createImage(int width, int height) {
        return delegateComponent.createImage(width, height);
    }

    @Override
    public VolatileImage createVolatileImage(int width, int height) {
        return delegateComponent.createVolatileImage(width, height);
    }

    @Override
    public VolatileImage createVolatileImage(int width, int height, ImageCapabilities caps) throws AWTException {
        return delegateComponent.createVolatileImage(width, height, caps);
    }

    @Override
    public void deliverEvent(Event e) {
        delegateComponent.deliverEvent(e);
    }

    @Override
    public void disable() {
        delegateComponent.disable();
    }

    @Override
    public void doLayout() {
        delegateComponent.doLayout();
    }

    @Override
    public void enable() {
        delegateComponent.enable();
    }

    @Override
    public void enable(boolean b) {
        delegateComponent.enable(b);
    }

    @Override
    public void enableInputMethods(boolean enable) {
        delegateComponent.enableInputMethods(enable);
    }

    @Override
    public AccessibleContext getAccessibleContext() {
        return delegateComponent.getAccessibleContext();
    }

    @Override
    public float getAlignmentX() {
        return delegateComponent.getAlignmentX();
    }

    @Override
    public float getAlignmentY() {
        return delegateComponent.getAlignmentY();
    }

    @Override
    public Color getBackground() {
        return delegateComponent.getBackground();
    }

    @Override
    public int getBaseline(int width, int height) {
        return delegateComponent.getBaseline(width, height);
    }

    @Override
    public BaselineResizeBehavior getBaselineResizeBehavior() {
        return delegateComponent.getBaselineResizeBehavior();
    }

    @Override
    public Rectangle getBounds() {
        return delegateComponent.getBounds();
    }

    @Override
    public Rectangle getBounds(Rectangle rv) {
        return delegateComponent.getBounds(rv);
    }

    @Override
    public ColorModel getColorModel() {
        return delegateComponent.getColorModel();
    }

    @Override
    public Component getComponentAt(int x, int y) {
        return delegateComponent.getComponentAt(x, y);
    }

    @Override
    public Component getComponentAt(Point p) {
        return delegateComponent.getComponentAt(p);
    }

    @Override
    public synchronized ComponentListener[] getComponentListeners() {
        return delegateComponent.getComponentListeners();
    }

    @Override
    public ComponentOrientation getComponentOrientation() {
        return delegateComponent.getComponentOrientation();
    }

    @Override
    public Cursor getCursor() {
        return delegateComponent.getCursor();
    }

    @Override
    public synchronized DropTarget getDropTarget() {
        return delegateComponent.getDropTarget();
    }

    @Override
    public Container getFocusCycleRootAncestor() {
        return delegateComponent.getFocusCycleRootAncestor();
    }

    @Override
    public synchronized FocusListener[] getFocusListeners() {
        return delegateComponent.getFocusListeners();
    }

    @Override
    public Set<AWTKeyStroke> getFocusTraversalKeys(int id) {
        return delegateComponent.getFocusTraversalKeys(id);
    }

    @Override
    public boolean getFocusTraversalKeysEnabled() {
        return delegateComponent.getFocusTraversalKeysEnabled();
    }

    @Override
    public Font getFont() {
        return delegateComponent.getFont();
    }

    @Override
    public FontMetrics getFontMetrics(Font font) {
        return delegateComponent.getFontMetrics(font);
    }

    @Override
    public Color getForeground() {
        return delegateComponent.getForeground();
    }

    @Override
    public Graphics getGraphics() {
        return delegateComponent.getGraphics();
    }

    @Override
    public GraphicsConfiguration getGraphicsConfiguration() {
        return delegateComponent.getGraphicsConfiguration();
    }

    @Override
    public int getHeight() {
        return delegateComponent.getHeight();
    }

    @Override
    public synchronized HierarchyBoundsListener[] getHierarchyBoundsListeners() {
        return delegateComponent.getHierarchyBoundsListeners();
    }

    @Override
    public synchronized HierarchyListener[] getHierarchyListeners() {
        return delegateComponent.getHierarchyListeners();
    }

    @Override
    public boolean getIgnoreRepaint() {
        return delegateComponent.getIgnoreRepaint();
    }

    @Override
    public InputContext getInputContext() {
        return delegateComponent.getInputContext();
    }

    @Override
    public synchronized InputMethodListener[] getInputMethodListeners() {
        return delegateComponent.getInputMethodListeners();
    }

    @Override
    public InputMethodRequests getInputMethodRequests() {
        return delegateComponent.getInputMethodRequests();
    }

    @Override
    public synchronized KeyListener[] getKeyListeners() {
        return delegateComponent.getKeyListeners();
    }

    @Override
    public <T extends EventListener> T[] getListeners(Class<T> listenerType) {
        return delegateComponent.getListeners(listenerType);
    }

    @Override
    public Locale getLocale() {
        return delegateComponent.getLocale();
    }

    @Override
    public Point getLocation() {
        return delegateComponent.getLocation();
    }

    @Override
    public Point getLocation(Point rv) {
        return delegateComponent.getLocation(rv);
    }

    @Override
    public Point getLocationOnScreen() {
        return delegateComponent.getLocationOnScreen();
    }

    @Override
    public Dimension getMaximumSize() {
        return delegateComponent.getMaximumSize();
    }

    @Override
    public Dimension getMinimumSize() {
        return delegateComponent.getMinimumSize();
    }

    @Override
    public synchronized MouseListener[] getMouseListeners() {
        return delegateComponent.getMouseListeners();
    }

    @Override
    public synchronized MouseMotionListener[] getMouseMotionListeners() {
        return delegateComponent.getMouseMotionListeners();
    }

    @Override
    public Point getMousePosition() throws HeadlessException {
        return delegateComponent.getMousePosition();
    }

    @Override
    public synchronized MouseWheelListener[] getMouseWheelListeners() {
        return delegateComponent.getMouseWheelListeners();
    }

    @Override
    public String getName() {
        return delegateComponent.getName();
    }

    @Override
    public Container getParent() {
        return delegateComponent.getParent();
    }

    @Override
    public Dimension getPreferredSize() {
        return delegateComponent.getPreferredSize();
    }

    @Override
    public synchronized PropertyChangeListener[] getPropertyChangeListeners() {
        return delegateComponent.getPropertyChangeListeners();
    }

    @Override
    public synchronized PropertyChangeListener[] getPropertyChangeListeners(String propertyName) {
        return delegateComponent.getPropertyChangeListeners(propertyName);
    }

    @Override
    public Dimension getSize() {
        return delegateComponent.getSize();
    }

    @Override
    public Dimension getSize(Dimension rv) {
        return delegateComponent.getSize(rv);
    }

    @Override
    public Toolkit getToolkit() {
        return delegateComponent.getToolkit();
    }

    @Override
    public int getWidth() {
        return delegateComponent.getWidth();
    }

    @Override
    public int getX() {
        return delegateComponent.getX();
    }

    @Override
    public int getY() {
        return delegateComponent.getY();
    }

    @Override
    public boolean gotFocus(Event evt, Object what) {
        return delegateComponent.gotFocus(evt, what);
    }

    @Override
    public boolean handleEvent(Event evt) {
        return delegateComponent.handleEvent(evt);
    }

    @Override
    public boolean hasFocus() {
        return delegateComponent.hasFocus();
    }

    @Override
    public void hide() {
        delegateComponent.hide();
    }

    @Override
    public boolean imageUpdate(Image img, int infoflags, int x, int y, int w, int h) {
        return delegateComponent.imageUpdate(img, infoflags, x, y, w, h);
    }

    @Override
    public boolean inside(int x, int y) {
        return delegateComponent.inside(x, y);
    }

    @Override
    public void invalidate() {
        delegateComponent.invalidate();
    }

    @Override
    public boolean isBackgroundSet() {
        return delegateComponent.isBackgroundSet();
    }

    @Override
    public boolean isCursorSet() {
        return delegateComponent.isCursorSet();
    }

    @Override
    public boolean isDisplayable() {
        return delegateComponent.isDisplayable();
    }

    @Override
    public boolean isDoubleBuffered() {
        return delegateComponent.isDoubleBuffered();
    }

    @Override
    public boolean isEnabled() {
        return delegateComponent.isEnabled();
    }

    @Override
    public boolean isFocusCycleRoot(Container container) {
        return delegateComponent.isFocusCycleRoot(container);
    }

    @Override
    public boolean isFocusOwner() {
        return delegateComponent.isFocusOwner();
    }

    @Override
    public boolean isFocusTraversable() {
        return delegateComponent.isFocusTraversable();
    }

    @Override
    public boolean isFocusable() {
        return delegateComponent.isFocusable();
    }

    @Override
    public boolean isFontSet() {
        return delegateComponent.isFontSet();
    }

    @Override
    public boolean isForegroundSet() {
        return delegateComponent.isForegroundSet();
    }

    @Override
    public boolean isLightweight() {
        return delegateComponent.isLightweight();
    }

    @Override
    public boolean isMaximumSizeSet() {
        return delegateComponent.isMaximumSizeSet();
    }

    @Override
    public boolean isMinimumSizeSet() {
        return delegateComponent.isMinimumSizeSet();
    }

    @Override
    public boolean isOpaque() {
        return delegateComponent.isOpaque();
    }

    @Override
    public boolean isPreferredSizeSet() {
        return delegateComponent.isPreferredSizeSet();
    }

    @Override
    public boolean isShowing() {
        return delegateComponent.isShowing();
    }

    @Override
    public boolean isValid() {
        return delegateComponent.isValid();
    }

    @Override
    public boolean isVisible() {
        return delegateComponent.isVisible();
    }

    @Override
    public boolean keyDown(Event evt, int key) {
        return delegateComponent.keyDown(evt, key);
    }

    @Override
    public boolean keyUp(Event evt, int key) {
        return delegateComponent.keyUp(evt, key);
    }

    @Override
    public void layout() {
        delegateComponent.layout();
    }

    @Override
    public void list() {
        delegateComponent.list();
    }

    @Override
    public void list(PrintStream out) {
        delegateComponent.list(out);
    }

    @Override
    public void list(PrintStream out, int indent) {
        delegateComponent.list(out, indent);
    }

    @Override
    public void list(PrintWriter out) {
        delegateComponent.list(out);
    }

    @Override
    public void list(PrintWriter out, int indent) {
        delegateComponent.list(out, indent);
    }

    @Override
    public Component locate(int x, int y) {
        return delegateComponent.locate(x, y);
    }

    @Override
    public Point location() {
        return delegateComponent.location();
    }

    @Override
    public boolean lostFocus(Event evt, Object what) {
        return delegateComponent.lostFocus(evt, what);
    }

    @Override
    public Dimension minimumSize() {
        return delegateComponent.minimumSize();
    }

    @Override
    public boolean mouseDown(Event evt, int x, int y) {
        return delegateComponent.mouseDown(evt, x, y);
    }

    @Override
    public boolean mouseDrag(Event evt, int x, int y) {
        return delegateComponent.mouseDrag(evt, x, y);
    }

    @Override
    public boolean mouseEnter(Event evt, int x, int y) {
        return delegateComponent.mouseEnter(evt, x, y);
    }

    @Override
    public boolean mouseExit(Event evt, int x, int y) {
        return delegateComponent.mouseExit(evt, x, y);
    }

    @Override
    public boolean mouseMove(Event evt, int x, int y) {
        return delegateComponent.mouseMove(evt, x, y);
    }

    @Override
    public boolean mouseUp(Event evt, int x, int y) {
        return delegateComponent.mouseUp(evt, x, y);
    }

    @Override
    public void move(int x, int y) {
        delegateComponent.move(x, y);
    }

    @Override
    public void nextFocus() {
        delegateComponent.nextFocus();
    }

    @Override
    public void paintAll(Graphics g) {
        delegateComponent.paintAll(g);
    }

    @Override
    public boolean postEvent(Event e) {
        return delegateComponent.postEvent(e);
    }

    @Override
    public Dimension preferredSize() {
        return delegateComponent.preferredSize();
    }

    @Override
    public boolean prepareImage(Image image, ImageObserver observer) {
        return delegateComponent.prepareImage(image, observer);
    }

    @Override
    public boolean prepareImage(Image image, int width, int height, ImageObserver observer) {
        return delegateComponent.prepareImage(image, width, height, observer);
    }

    @Override
    public void print(Graphics g) {
        delegateComponent.print(g);
    }

    @Override
    public void printAll(Graphics g) {
        delegateComponent.printAll(g);
    }

    @Override
    public synchronized void remove(MenuComponent popup) {
        delegateComponent.remove(popup);
    }

    @Override
    public synchronized void removeComponentListener(ComponentListener l) {
        delegateComponent.removeComponentListener(l);
    }

    @Override
    public synchronized void removeFocusListener(FocusListener l) {
        delegateComponent.removeFocusListener(l);
    }

    @Override
    public void removeHierarchyBoundsListener(HierarchyBoundsListener l) {
        delegateComponent.removeHierarchyBoundsListener(l);
    }

    @Override
    public void removeHierarchyListener(HierarchyListener l) {
        delegateComponent.removeHierarchyListener(l);
    }

    @Override
    public synchronized void removeInputMethodListener(InputMethodListener l) {
        delegateComponent.removeInputMethodListener(l);
    }

    @Override
    public synchronized void removeKeyListener(KeyListener l) {
        delegateComponent.removeKeyListener(l);
    }

    @Override
    public synchronized void removeMouseListener(MouseListener l) {
        delegateComponent.removeMouseListener(l);
    }

    @Override
    public synchronized void removeMouseMotionListener(MouseMotionListener l) {
        delegateComponent.removeMouseMotionListener(l);
    }

    @Override
    public synchronized void removeMouseWheelListener(MouseWheelListener l) {
        delegateComponent.removeMouseWheelListener(l);
    }

    @Override
    public void removeNotify() {
        delegateComponent.removeNotify();
    }

    @Override
    public synchronized void removePropertyChangeListener(PropertyChangeListener listener) {
        delegateComponent.removePropertyChangeListener(listener);
    }

    @Override
    public synchronized void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) {
        delegateComponent.removePropertyChangeListener(propertyName, listener);
    }

    @Override
    public void repaint() {
        delegateComponent.repaint();
    }

    @Override
    public void repaint(long tm) {
        delegateComponent.repaint(tm);
    }

    @Override
    public void repaint(int x, int y, int width, int height) {
        delegateComponent.repaint(x, y, width, height);
    }

    @Override
    public void repaint(long tm, int x, int y, int width, int height) {
        delegateComponent.repaint(tm, x, y, width, height);
    }

    @Override
    public void requestFocus() {
        delegateComponent.requestFocus();
    }

    @Override
    public boolean requestFocusInWindow() {
        return delegateComponent.requestFocusInWindow();
    }

    @Override
    public void reshape(int x, int y, int width, int height) {
        delegateComponent.reshape(x, y, width, height);
    }

    @Override
    public void resize(int width, int height) {
        delegateComponent.resize(width, height);
    }

    @Override
    public void resize(Dimension d) {
        delegateComponent.resize(d);
    }

    @Override
    public void setBackground(Color c) {
        //TODO delegateComponent.setBackground(c);
    }

    @Override
    public void setBounds(int x, int y, int width, int height) {
        delegateComponent.setBounds(x, y, width, height);
    }

    @Override
    public void setBounds(Rectangle r) {
        delegateComponent.setBounds(r);
    }

    @Override
    public void setComponentOrientation(ComponentOrientation o) {
        delegateComponent.setComponentOrientation(o);
    }

    @Override
    public void setCursor(Cursor cursor) {
        delegateComponent.setCursor(cursor);
    }

    @Override
    public synchronized void setDropTarget(DropTarget dt) {
        delegateComponent.setDropTarget(dt);
    }

    @Override
    public void setEnabled(boolean b) {
        delegateComponent.setEnabled(b);
    }

    @Override
    public void setFocusTraversalKeys(int id, Set<? extends AWTKeyStroke> keystrokes) {
        delegateComponent.setFocusTraversalKeys(id, keystrokes);
    }

    @Override
    public void setFocusTraversalKeysEnabled(boolean focusTraversalKeysEnabled) {
        delegateComponent.setFocusTraversalKeysEnabled(focusTraversalKeysEnabled);
    }

    @Override
    public void setFocusable(boolean focusable) {
        delegateComponent.setFocusable(focusable);
    }

    @Override
    public void setFont(Font f) {
        delegateComponent.setFont(f);
    }

    @Override
    public void setForeground(Color c) {
        delegateComponent.setForeground(c);
    }

    @Override
    public void setIgnoreRepaint(boolean ignoreRepaint) {
        delegateComponent.setIgnoreRepaint(ignoreRepaint);
    }

    @Override
    public void setLocale(Locale l) {
        delegateComponent.setLocale(l);
    }

    @Override
    public void setLocation(int x, int y) {
        delegateComponent.setLocation(x, y);
    }

    @Override
    public void setLocation(Point p) {
        delegateComponent.setLocation(p);
    }

    @Override
    public void setMaximumSize(Dimension maximumSize) {
        delegateComponent.setMaximumSize(maximumSize);
    }

    @Override
    public void setMinimumSize(Dimension minimumSize) {
        delegateComponent.setMinimumSize(minimumSize);
    }

    @Override
    public void setName(String name) {
        delegateComponent.setName(name);
    }

    @Override
    public void setPreferredSize(Dimension preferredSize) {
        delegateComponent.setPreferredSize(preferredSize);
    }

    @Override
    public void setSize(int width, int height) {
        delegateComponent.setSize(width, height);
    }

    @Override
    public void setSize(Dimension d) {
        delegateComponent.setSize(d);
    }

    @Override
    public void setVisible(boolean b) {
        delegateComponent.setVisible(b);
    }

    @Override
    public void show() {
        delegateComponent.show();
    }

    @Override
    public void show(boolean b) {
        delegateComponent.show(b);
    }

    @Override
    public Dimension size() {
        return delegateComponent.size();
    }

    @Override
    public String toString() {
        return delegateComponent.toString();
    }

    @Override
    public void transferFocus() {
        delegateComponent.transferFocus();
    }

    @Override
    public void transferFocusBackward() {
        delegateComponent.transferFocusBackward();
    }

    @Override
    public void transferFocusUpCycle() {
        delegateComponent.transferFocusUpCycle();
    }

    @Override
    public void update(Graphics g) {
        delegateComponent.update(g);
    }

    @Override
    public void validate() {
        delegateComponent.validate();
    }
}
